<link type="text/css" href="<?php echo base_url();?>assets/js/development-bundle/themes/ui-lightness/jquery.ui.all.css" rel="stylesheet" />
<script type="text/javascript" src="<?php echo base_url();?>assets/js/development-bundle/ui/jquery.ui.core.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>assets/js/development-bundle/ui/jquery.ui.datepicker.js"></script>
<script type="text/javascript" src="<?php echo base_url() ?>/assets/js/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
tinyMCE.init({
	mode : "textareas",
	width: 200,
	skin : "default",
	theme : "advanced",
	theme_advanced_toolbar_location : "top",
	theme_advanced_buttons1 : "bold,italic,underline,|,justifyleft,justifycenter,justifyright,justifyfull,|,numlist,|,outdent,indent,|,undo,redo,|,forecolor,backcolor",
	theme_advanced_buttons2 : "",
	theme_advanced_buttons3 : ""
});
function back(){
	document.location="<?php echo site_url(); ?>/Pasien";
}
$(document).ready(function(){
$(".tgl").datepicker({
	changeMonth: true,
	changeYear: true,
	monthNamesShort: [ "Januari", "Februari", "Maret", "April", "Mei", "Juni", "Juli", "Agustus", "September", "Oktober", "Nopember", "Desember" ],
	dayNames: [ "Minggu", "Senin", "Selasa", "Rabu", "Kamis", "Jumat", "Sabtu" ],
	dayNamesMin: [ "M", "S", "S", "R", "K", "J", "S" ],
	showOn: "button",
	buttonImage: "<?php echo base_url(); ?>assets/images/calendar.gif",
	buttonImageOnly: true
});
$( ".tgl" ).datepicker( "option", "dateFormat", "yy-mm-dd" );
var tgl_lahir = document.formPasien.elements["tgl_lahir"].value;
if(tgl_lahir != ""){
	countAge();
}
});
function countAge(){
	var	date= new Date();
	var dd	= date.getDate();
	var mm	= date.getMonth()+1;
	var	yy	= date.getFullYear();
	var bDate	= document.formPasien.elements["tgl_lahir"].value;
	var val		= bDate.split("-");
	if((mm - val[1]) >= 0){
		if((mm - val[1]) == 0){
			if((dd - val[2]) >= 0){
				var age	= yy - val[0];
			} else {
				var age	= yy - val[0] - 1;
				if(age < 0){
					var age = 0;
				}
			}
		} else {
			var age	= yy - val[0];
		}
	} else {
		var age	= yy - val[0] - 1;
		if(age < 0){
			var age = 0;
		}
	}
	document.forms['formPasien'].elements['umur'].value	= age;
}

</script>
<style>
.ui-widget {
		font-family:arial;
		font-size: 10pt;
		font-weight:normal;
		color:black;
	}
	.ui-datepicker-month{
		float:left;
	}
	.ui-datepicker-year{
		float:left;
	}
	.ui-datepicker-title{
		width:172px;
	}
</style>
<div class="form-head">Form Pasien</div>
<hr>
<?php
echo form_open("/Pasien/formPasien/".$parameter, array("name"=>"formPasien","id"=>"medic_form"));
if($parameter == FALSE){
	$no_reg		= set_value("no_reg");
	$nama_pasien= set_value("nama_pasien");
	$alamat		= set_value("alamat");
	$tgl_daftar	= set_value("tgl_daftar");
	$jenkel		= set_value("jenis_kelamin");
	$tgl_lahir	= set_value("tgl_lahir");
} else {
	$no_reg		= $value["NO_REG"];
	$nama_pasien= $value["NAMA_PASIEN"];
	$alamat		= $value["ALAMAT"];
	$tgl_daftar	= $value["TGL_DAFTAR"];
	$jenkel		= $value["JENIS_KELAMIN"];
	$tgl_lahir	= $value["TGL_LAHIR"];
}
?>
<p>
	<label>Nomor Registrasi</label>
	<input type="text" name="no_reg" value="<?php echo $no_reg; ?>">
	<?php echo form_error("no_reg"); ?>
</p>
<p>
	<label>Nama Pasien</label>
	<input type="text" name="nama_pasien" value="<?php echo $nama_pasien; ?>">
	<?php echo form_error("nama_pasien"); ?>
</p>
<p>
	<label>Alamat</label>
	<textarea name="alamat"><?php echo $alamat;  ?></textarea>
	<?php echo form_error("alamat"); ?>
</p>
<p>
	<label>Tanggal Daftar</label>
	<input type="text" name="tgl_daftar" class="tgl" value="<?php echo $tgl_daftar; ?>" readonly>
	<?php echo form_error("tgl_daftar"); ?>
</p>
<p>
	<label>Tanggal Lahir</label>
	<input type="text" name="tgl_lahir" onChange="countAge()" class="tgl" value="<?php echo $tgl_lahir; ?>" readonly>
	<?php echo form_error("tgl_lahir"); ?>
</p>
<p>
	<label>Umur</label>
	<input type="text" name="umur" value="" disabled>
</p>
<p>
	<label>Jenis Kelamin</label>
	<label class="radio">
		<input type="radio" name="jenis_kelamin" value="1" id="optionsRadios1" <?php echo $jenkel == 1 ? "checked" : "" ?>> Laki - Laki
	</label>
	<label class="radio">
		<input type="radio" name="jenis_kelamin" value="0" id="optionsRadios2" <?php echo $jenkel == 0 ? "checked" : "" ?>> Perempuan
	</label>
	<?php echo form_error("jenis_kelamin"); ?>
</p>
<p>
	<input type="submit" class="btn btn-success" id="submit" value="Simpan">
	<input type="reset" class="btn btn-success" id="submit" value="Reset">
	<input type="button" class="btn btn-success" id="submit" value="Kembali" onClick="back()">
</p>
<?php echo form_close(); ?>